package main

import (
	"errors"
	"go-soap"
	"net/http"
)

type UserRequest struct {
	Id int64
}

type UserResponse struct {
	ReturnInfo string
}

type User struct{}

func (u User) Do(req interface{}, resp interface{}) error {
	return errors.New("错误")
}

func (u User) Name() string {
	return "User"
}

func (u User) ReqStruct() interface{} {
	return UserRequest{}
}

func (u User) RespStruct() interface{} {
	return UserResponse{}
}

type DataListRequest struct {
	Page    int
	PerPage int
	Search  string
}

type DataListResponse struct {
	Info []DataValue
}

type DataValue struct {
	Data string
	ID   int64
}

type DataList struct {
}

func (d DataList) Do(req interface{}, resp interface{}) error {
	res := resp.(*DataListResponse)
	res.Info = []DataValue{
		{
			Data: "data1",
			ID:   1,
		},
		{
			Data: "data2",
			ID:   2,
		},
	}
	return nil
}

func (d DataList) Name() string {
	return "DataList"
}

func (d DataList) ReqStruct() interface{} {
	return DataListRequest{}
}

func (d DataList) RespStruct() interface{} {
	return DataListResponse{}
}

func main() {
	s := soap.NewServer("people", "http://10.0.200.205:8081/people")
	s.RegisterMethod(User{})
	s.RegisterMethod(DataList{})
	http.HandleFunc("/people", s.Handler)
	http.ListenAndServe("10.0.200.205:8081", nil)
}
